000100******************************************************************
000200*PROGRAM : Change instructor information                         *
000300*AUTHOR  : H. James Vo                                           *
000400******************************************************************
000700 IDENTIFICATION DIVISION.
000800 PROGRAM-ID. INST-C.

      *-----------------------------------------------------------------
000900 ENVIRONMENT DIVISION.
001000     SELECT IOFILE       ASSIGN TO "INSTMST.DAT"
001100                         ORGANIZATION    IS INDEXED
001200                         ACCESS          IS RANDOM
001300                         RECORD KEY      IS IO-INST-ID
001400                         ALTERNATE KEY   IS IO-INST-NAME WITH
001500                                         DUPLICATES
001600                         FILE STATUS     IS WS-STAT.
001700
002500*-----------------------------------------------------------------
002600 DATA DIVISION.
002700 FILE SECTION.
002800 FD  IOFILE.
002900 01  STUDENT-RECORD.
003000     03  IO-INST-ID      PIC 9(3).
003100     03  IO-INST-NAME    PIC X(20).
003500     03  IO-INST-A       PIC X.

004200 WORKING-STORAGE SECTION.
004300 01  WS-STAT             PIC XX.
004500 01  WS-EOF              PIC X VALUE 'N'.
004600 01  WS-INST-ID          PIC 9(4).
004700 01  WS-INST-NAME        PIC X(20).
005100 01  WS-INST-A           PIC X.
005200 01  WS-DATE.
005300     03  WS-YEAR         PIC 99.
005400     03  WS-MONTH        PIC 99.
005500     03  WS-DAY          PIC 99.
       01  WS-CHG              PIC X VALUE 'N'.
005600 01  WS-ERR              PIC X VALUE 'N'.
005700 01  WS-CONT             PIC X VALUE 'Y'.
005800 01  WS-FIRST            PIC X VALUE 'Y'.
005900
006000 SCREEN SECTION.
006100 01  INPUT-INST-ID-SCRN.
006200         05  BLANK SCREEN.
006300         05  LINE 1  COL 01  VALUE "UPDATE INSTRUCTOR".
006400         05          COL 73  PIC 9(2) FROM WS-MONTH.
006500         05          COL 75  VALUE "/".
006600         05          COL 76  PIC 9(2) FROM WS-DAY.
006700         05          COL 78  VALUE "/".
006800         05          COL 79  PIC 9(2) FROM WS-YEAR.
006900         05  LINE 2  COL 35  VALUE "UPDATE INSTRUCTOR".
007000
007100         05  LINE 4  COL 15  VALUE "INSTRUCTOR ID TO UPDATE".
007200         05          COL 40  PIC 9(3) TO WS-INST-ID.
007300         05  LINE 6  COL 34  VALUE "(ENTER 000 TO EXIT)".
007400
007500 01  INPUT-SCRN.
007600         05  BLANK SCREEN.
007700         05  LINE 1  COL 01  VALUE "UPDATE INSTRUCTOR".
007800         05          COL 73  PIC 9(2) FROM WS-MONTH.
007900         05          COL 75  VALUE "/".
008000         05          COL 76  PIC 9(2) FROM WS-DAY.
008100         05          COL 78  VALUE "/".
008200         05          COL 79  PIC 9(2) FROM WS-YEAR.
008300         05  LINE 2  COL 35  VALUE "UPDATE INSTRUCTOR".
008400         05  LINE 4  COL 15  VALUE "INSTRUCTOR ID TO UPDATE".
008500         05          COL 40  PIC 9(3) FROM WS-INST-ID.
008600
008700         05  INPUT-NAME-SCRN.
008800             10  LINE 5  COL 20  VALUE "INSTRUCTOR NAME".
008900             10          COL 40  PIC X(20) FROM IO-INST-NAME.
009000             10  LINE 6  COL 40  PIC X(20) TO   WS-INST-NAME.
                   10  LINE 7  COL 20  VALUE "EX: H.  Keller (TWO SPACES
      -                                " AFTER THE FIRST INITIAL)".
011300
011400         05  INPUT-ACTIVE-SCRN.
011500             10  LINE 9  COL 20  VALUE "ACTIVATE (Y/N)?".
011600             10          COL 40  PIC X TO WS-INST-A AUTO.
011700         05  LINE 11     COL 27  VALUE "(LEAVE BLANK TO KEEP OLD V
011800-            "ALUES)".
011900
012000 01  ERROR-SCRN.
012100     03  BLANK SCREEN.
012200     03  LINE 12 COL 32 VALUE "ERROR UPDATING RECORD".
012300     03  LINE 14 COL 32 VALUE "FILE STATUS:".
012400     03          COL 46 PIC XX FROM WS-STAT.
012500     03  LINE 15 COL 32 VALUE "RECORD KEY:".
012600     03          COL 46 PIC X(8) FROM WS-INST-ID.
012700     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
012800     03          COL 47 PIC X TO WS-CONT AUTO.
012900
009100 01  CHG-REC-SCRN.
009200     03  BLANK SCREEN.
009300     03  LINE 4  COL 20 VALUE "INSTRUCTOR ID".
009400     03          COL 40 PIC X(3) FROM WS-INST-ID.
009500     03  LINE 5  COL 20 VALUE "INSTRUCTOR NAME".
009600     03          COL 40 PIC X(20) FROM WS-INST-NAME.
010100     03  LINE 8  COL 20 VALUE "ACTIVATE (Y/N)?".
010200     03          COL 40 PIC X FROM WS-INST-A.
010300     03  LINE 9  COL 25 VALUE "DO YOU WANT TO MODIFY RECORD (Y/N)?
      -                             "".
010400     03          COL 65 PIC X TO WS-CHG AUTO.
014000
       01  SUCCESS-SCRN.
014100     03  BLANK SCREEN.
014200     03  LINE 12 COL 27 VALUE "RECORD UPDATED SUCCESSFULLY".
014300     03  LINE 18 COL 33 VALUE "CONTINUE(Y/N)?".
014400     03          COL 47 PIC X TO WS-CONT AUTO.
014500
014600*-----------------------------------------------------------------
014700 PROCEDURE DIVISION.
014800 100-MAIN.
014900     ACCEPT WS-DATE FROM DATE
015100     OPEN I-O   IOFILE
015400
           MOVE ZEROS  TO WS-INST-ID
015500     MOVE SPACES TO WS-INST-NAME
016000
016100     MOVE 'Y' TO WS-FIRST
016200     MOVE 'Y' TO WS-CONT
016300
016400     PERFORM 200-UPDATE
016500     UNTIL (WS-INST-ID = ZEROS AND WS-FIRST = 'N')
016600     OR WS-CONT = 'N'
016700
016800     CLOSE IOFILE
017000
017100     EXIT PROGRAM.
017200
017300 200-UPDATE.

017500     MOVE ZEROS  TO WS-INST-ID
017600     MOVE SPACES TO WS-INST-NAME
018000
           MOVE 'N' TO WS-CHG
018100     MOVE 'N' TO WS-FIRST
018200     DISPLAY INPUT-INST-ID-SCRN
018300     ACCEPT  INPUT-INST-ID-SCRN
018400
018500     MOVE "N" TO WS-ERR
018600
018700     IF NOT WS-INST-ID = ZEROS
018800
018900         MOVE WS-INST-ID TO IO-INST-ID
019000
019100         READ IOFILE
019200             INVALID KEY MOVE "Y" TO WS-ERR
019300         END-READ
019400
019500         IF NOT WS-ERR = "Y"
020500
020600             DISPLAY INPUT-SCRN
020800             ACCEPT  INPUT-NAME-SCRN
                   ACCEPT  INPUT-ACTIVE-SCRN
023100
022400             IF NOT WS-ERR = 'Y'

023600                 IF NOT WS-INST-NAME = SPACES
023700                     MOVE WS-INST-NAME TO IO-INST-NAME
023800                 END-IF
025100
025200                 IF NOT WS-INST-A = SPACES
025300                     MOVE WS-INST-A    TO IO-INST-A
025400                 END-IF
025500
025600                 MOVE 'N' TO WS-ERR
025700
                       DISPLAY CHG-REC-SCRN
                       ACCEPT  CHG-REC-SCRN

                       IF WS-CHG = 'Y'
025800                     REWRITE STUDENT-RECORD
025900                         INVALID KEY MOVE 'Y' TO WS-ERR
026000                     END-REWRITE
                       ELSE
                           PERFORM 200-UPDATE
                       END-IF
026100
026200                 IF WS-ERR = 'Y'
026300                     DISPLAY ERROR-SCRN
026400                     ACCEPT  ERROR-SCRN
026500                 ELSE
026600                     DISPLAY SUCCESS-SCRN
026700                     ACCEPT  SUCCESS-SCRN
026800                 END-IF
026900
027300             END-IF
027400
027500         ELSE
027600             DISPLAY ERROR-SCRN
027700             ACCEPT  ERROR-SCRN
027800         END-IF
027900     END-IF.
028000
